<template>
  <div class="container">
    <div class="header" v-if="bannerdata">
      <el-carousel height="100vh" motion-blur>
        <el-carousel-item indicator-position="none" v-for="item in bannerdata" :key="item._id">
          <img :src="item.url" alt="" class="img" />
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="main">
      <div class="leftside">
        <Leftside></Leftside>
      </div>
      <div class="center">
        <Listitem :data="articledata"></Listitem>
        <el-pagination
          background
          layout="prev, pager, next"
          :page-size="pagination.size"
          @current-change="hanldlecurrent"
          v-model="pagination.currentpage"
          :total="pagination.count">
        </el-pagination>
      </div>
      <div class="rightside">
        <RightsideVue :data="articledata"></RightsideVue>
      </div>
    </div>

  </div>
</template>

<script setup>
import Listitem from '@/components/Listitem.vue'
import Leftside from '@/components/Leftside.vue'
import RightsideVue from '@/components/Rightside.vue'
import {searchdata} from "../../apis/article";
import {searchbannerdata} from "../../apis/banner";
import { onMounted, ref } from 'vue'
// import axios from 'axios';
onMounted(()=>{
  getbannerdata()
  getarticledata()
})
const articledata = ref([])
const getarticledata = () =>{
  let params = {
    page: pagination.value.currentpage,
    size: pagination.value.size
  }
  searchdata(params).then((res)=>{
    if (res.data.isok) {
      articledata.value = res.data.data
      pagination.value.count = res.data.count
      console.log(articledata.value, 'data')
    }
  })
  // axios.post(`/article`,{}).then((ret) => {
  //   console.log(ret.data)
  // })
}
const pagination = ref({
  currentpage: 1,
  size: 10,
  count: 0
})
const hanldlecurrent = (currentpage) => {
  pagination.value.currentpage = currentpage
  getarticledata()
}
const bannerdata = ref([])
const getbannerdata = ()=>{
  searchbannerdata().then((res)=>{
    bannerdata.value = res.data
    console.log(bannerdata.value, 'data')
  })
}
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  min-height: 100vh;
  background-color: #f5f5ff;
}
.header {
  padding-bottom: 10px;
  .img{
    width: 100%;
    object-fit: cover;
  }
}
.main {
  display: flex;
  justify-content: center;
  .leftside {
  }
  .center {
    padding: 0 10px;
  }
}
</style>
